/**
 * 
 */
package com.hz.winnie.demands.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hz.winnie.demands.pojo.Product;

/**
 * @description 产品DAO实现
 * @author winnie
 * @date 2011-4-23
 * @version 1.0
 */
public class ProductDaoImpl extends SqlMapClientDaoSupport implements
		ProductDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.hz.winnie.demands.dao.ProductDao#getProductById(java.lang.String)
	 */
	@Override
	public Product getProductById(String productId) {
		return (Product) getSqlMapClientTemplate().queryForObject(
				"product.getProductById", productId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.hz.winnie.demands.dao.ProductDao#create(com.hz.winnie.demands.pojo
	 * .Product)
	 */
	@Override
	public int create(Product product) {
		return (Integer) getSqlMapClientTemplate().insert("product.create",
				product);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.hz.winnie.demands.dao.ProductDao#update(com.hz.winnie.demands.pojo
	 * .Product)
	 */
	@Override
	public void update(Product product) {
		getSqlMapClientTemplate().update("product.update", product);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hz.winnie.demands.dao.ProductDao#find(java.lang.Object)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Product> find(Product product) {
		return getSqlMapClientTemplate().queryForList("product.find", product);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hz.winnie.demands.dao.ProductDao#countAllProduct()
	 */
	@Override
	public int countAllProduct() {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"product.countAllProduct");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Product> getProductsByName(String name, String productId) {
		Map map = new HashMap();
		map.put("name", name);
		map.put("productId", productId);
		return (List<Product>) getSqlMapClientTemplate().queryForList(
				"product.getProductsByName", map);
	}
}
